<template>
  <van-popup
    v-model="showPopup"
    position="bottom"
    round
    :close-on-click-overlay="false"
    class="copy-password-popup"
    get-container="body"
    :overlay-style="{ zIndex: '9998' }"
    :style="{ height: '8rem' }"
  >
    <div class="header-popup">
      <div class="header-title">支付方式</div>
      <img
        src="https://commonresource-1252524126.cdn.xiaoeknow.com/image/ly3scl7e0wly.png"
        class="header-close"
        @click="closePopup"
      />
    </div>

    <div class="main-popup">
      <div class="main-money">
        <span>¥</span>
        <span>{{ price }}</span>
      </div>

      <div class="main-cont">
        <img
          src="https://commonresource-1252524126.cdn.xiaoeknow.com/image/ly3sbo5j0p0j.png"
          class="zfb-logo"
        />

        <div class="main-replicated" v-show="isCopyed">
          <img
            src="https://commonresource-1252524126.cdn.xiaoeknow.com/image/ly3sczeb0qm6.png"
            class="main-replicated-img"
          />
          已复制
        </div>

        <div class="main-tip">
          <img
            src="https://commonresource-1252524126.cdn.xiaoeknow.com/image/ly3sbybz0an7.png"
            class="main-tip-img"
          />
          复制吱口令，打开支付宝App完成付款
        </div>

        <div class="main-copy-cont">
          <div class="copy-code" v-text="orderInfo.share_code"></div>
          <div class="copy-text" @click="copyCode">复制</div>
        </div>
      </div>
      <div class="look" @click="goDetail">我已支付，查看订单</div>
    </div>
  </van-popup>
</template>

<script>
import { Popup } from "vant";

export default {
  components: {
    [Popup.name]: Popup,
  },
  props: {
    showPopup: {
      type: Boolean,
      default: true,
    },
    orderInfo: {
      type: Object,
      default: () => {},
    },
    price: {
      type: Number || String,
      default: "",
    },
    isCheckOrderState: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      isCopyed: false,
    };
  },
  methods: {
    // 关闭弹框
    closePopup() {
      this.$emit("changeShowCopy", false);
    },
    // 复制
    copyCode() {
      let oInput = document.createElement("input");
      oInput.value = this.orderInfo.share_code;
      document.body.appendChild(oInput);
      oInput.select(); // 选择对象
      document.execCommand("Copy"); // 执行浏览器复制命令
      oInput.style.display = "none";
      document.body.removeChild(oInput);
      this.$toast({
        message:'吱口令复制成功',
        className: "toastName",
      });
      this.isCopyed = true;
    },
    // 跳转订单详情页
    goDetail() {
      // 是否校验订单状态
      if (this.isCheckOrderState) {
        this.$emit("checkOrderState");
      } else {
        window.location.href = `${window.location.origin}/p/t/v1/ecommerce/h5_order/order/order_details?order_id=${this.orderInfo.order_id}`;
      }
    },
  },
};
</script>

<style>
.toastName {
  z-index: 10000 !important;
}
</style>
<style lang="scss" scoped>
.copy-password-popup {
  z-index: 9999 !important;
}

.header-popup {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 1);
  padding: 0.24rem 0;

  .header-title {
    color: rgba(51, 51, 51, 1);
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    font-family: "PingFang SC";
  }

  .header-close {
    width: 0.32rem;
    height: 0.32rem;
    position: absolute;
    right: 0.32rem;
    top: 0.32rem;
  }
}

.main-popup {
  width: 100%;
  margin-top: 0.64rem;
  .main-money {
    text-align: center;
    color: #333333;
    font-weight: 600;
    span:first-child {
      font-size: 0.48rem;
    }
    span:last-child {
      font-size: 0.8rem;
    }
  }

  .main-cont {
    margin-top: 0.98rem;
    height: 2.9rem;
    width: calc(100% - 0.64rem);
    margin-left: 0.32rem;
    margin-bottom: 0.66rem;
    border-radius: 0.24rem;
    background: #f5f5f5;
    padding: 0.64rem 0.32rem 0.32rem 0.32rem;
    box-sizing: border-box;
    position: relative;

    .zfb-logo {
      position: absolute;
      width: 0.64rem;
      height: 0.64rem;
      left: calc(50% - 0.32rem);
      top: -0.32rem;
    }

    .main-replicated {
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.28rem;
      font-weight: 600;
      margin-bottom: 0.24rem;

      .main-replicated-img {
        width: 0.32rem;
        height: 0.32rem;
        margin-right: 0.08rem;
      }
    }

    .main-tip {
      color: #333333;
      font-size: 0.24rem;
      font-weight: 600;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-bottom: 0.18rem;

      .main-tip-img {
        width: 0.36rem;
        height: 0.36rem;
        margin-right: 0.04rem;
      }
    }

    .main-copy-cont {
      width: 100%;
      border-radius: 0.4rem;
      background: #ffffff;
      position: relative;

      .copy-code {
        color: rgba(153, 153, 153, 1);
        font-size: 14px;
        font-weight: 500;
        height: 0.8rem;
        line-height: 0.8rem;
        padding-left: 0.32rem;
        border-radius: 0.4rem;
        width: calc(100% - 2rem);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .copy-text {
        width: 1.52rem;
        height: 0.56rem;
        line-height: 0.56rem;
        text-align: center;
        border-radius: 0.4rem;
        opacity: 1;
        background: rgba(20, 114, 255, 1);
        color: #ffffff;
        font-size: 0.28rem;
        font-weight: 600;
        position: absolute;
        right: 0.12rem;
        top: 0.12rem;
      }
    }
  }

  .look {
    color: #1472ff;
    font-size: 0.28rem;
    font-weight: 600;
    text-align: center;
  }
}
</style>
